
import BannerAPI from '../api/banner.js';

export const Banner={
   state:{
      bannerlist:[],
      banner_total_count:0,
      editBannerStatus:-1,     //插入状态 0失败  1成功  -1不改变
      bannerinfo:[],
      delBannerStatus:-1,       //删除状态
      allbannertype:[
        {value:1,label:'首页'},
        {value:2,label:'学习平台'},
        {value:3,label:'服务'},
        {value:4,label:'治理'},
        {value:5,label:'志愿服务'}
      ],
      //筛选条件
      search_banner_type:''
   },
   mutations:{
      setBannerList(state,list){
          state.bannerlist=list;
      },
      setBannerTotalCount(state,total_count){
          state.banner_total_count=total_count;
      },
      setEditBannerStatus(state,status){
          state.editBannerStatus=status;
      },
      setBannerInfo(state,info){
          state.bannerinfo=info;
      },
      setDelBannerStatus(state,status){
          state.delBannerStatus=status;
      },
      setAllBannerType(state,list){
          state.allbannertype=list;
      },
      setSearchBannerType(state,type){
          state.search_banner_type=type;
      }
   },
   actions:{
      loadBannerList(context,data){
          BannerAPI.getBannerList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setBannerList',response.data.list);
                  context.commit('setBannerTotalCount',response.data.total_count);
              }
          })
      },
      //插入Banner
      editBanner(context,data){
          BannerAPI.editBanner(data).then(function(response){
              context.commit('setEditBannerStatus',response.data.code);
          })
      },
      //获取详情
      loadBannerInfo(context,data){
          BannerAPI.getBannerInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setBannerInfo',response.data.info);
              }
          })
      },
      //删除
      delBanner(context,data){
          BannerAPI.delBanner(data).then(function(response){
                context.commit('setDelBannerStatus',response.data.code);
          })
      },
      loadAllBannerType(context,data){
         BannerAPI.getAllBannerType(data).then(function(response){
                context.commit('setAllBannerType',response.data.list);
         })
      }
   },
   getters:{
      getBannerList:state =>{
         return state.bannerlist
      },
      getBannerTotalCount: state =>{
         return state.banner_total_count
      },
      getEditBannerStatus:state=>{
          return state.editBannerStatus;
      },
      getBannerInfo:state => {
          return state.bannerinfo;
      },
      getDelBannerStatus:state => {
          return state.delBannerStatus;
      },
      getAllBannerType:state => {
          return state.allbannertype;
      },
      getSearchBannerType:state => {
          return state.search_banner_type;
      }
   }
}
